package com.ambow.servlet;

import java.io.IOException;

import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ambow.Entity.Operator;
import com.ambow.dao.Operat;


/**
 * Servlet implementation class Person_show
 */
@WebServlet("/Person_showServlet")
public class Person_showServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Person_showServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String ud=request.getParameter("update");
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("UTF-8");  
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		
		String info=request.getParameter("val");
		byte [] b=info.getBytes("iso-8859-1");
		info=new String(b,"utf-8");
		
		if(info.equals("personinfo")){//把从person_info.jsp页面传来的val和person相比较
			response.sendRedirect("pages/module/person/person001/user_detail.jsp");
		}
		else if(info.equals("role_qurey")){
			
			Operat operat = new Operat();
			List list = operat.roleQuery("库存管理员");
//			Operator operator = (Operator) list.get(0);
			
			request.setAttribute("operatorinfo", list);
			request.getRequestDispatcher("pages/module/system/system002/user_list.jsp").forward(request, response);
//			System.out.println(aops.getName());
//			response.sendRedirect("static/module/system/system002/user_list.jsp");
			
		}
		else if(info.equals("arole_query")){
			String role_query = request.getParameter("group1");
//			byte[] b=role_query.getBytes("iso-8859-1");
//			role_query=new String(b,"utf-8");
			Operat operat = new Operat();
			List list = operat.roleQuery(role_query);
			
			request.setAttribute("operatorinfo", list);
			request.getRequestDispatcher("pages/module/system/system002/user_list.jsp").forward(request, response);
			
		}else if(info.equals("xiugai")) {
			 int operator_id=Integer.valueOf(request.getParameter("account"));
			 Operat operat=new Operat();
			Operator op=operat.getOne(Operator.class, operator_id);
			HttpSession session=request.getSession();
			session.setAttribute("operator_id", op.getId());
			session.setAttribute("operator_name", op.getName());
			session.setAttribute("operator_posetion", op.getPosition());
			//String op_postion;
			//request.setAttribute("opPostion", op.getPosetion());
			session.setAttribute("operator_tel", op.getTel());
			//request.setAttribute("opTel", op.getTel());
			session.setAttribute("operator_role", op.getRole());
			//request.setAttribute("opRole", op.getRole());
			session.setAttribute("operator_remark", op.getRemark());
			//request.setAttribute("opRemark", op.getRemark());
			session.setAttribute("operator_password", op.getPassword());
			request.getRequestDispatcher("pages/module/person/person001/user_detail.jsp").forward(request, response);
			
		}else if(info.equals("delete")) {
			 int operator_id=Integer.valueOf(request.getParameter("account"));
			 Operat operat=new Operat();
			//	Operator op=operat.getOne(Operator.class, operator_id);
				operat.deleteOperator(operator_id);
				request.getRequestDispatcher("pages/module/system/system002/user_list.jsp").forward(request, response);
		}
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
		
	}

}
